<template>
  <div></div>
</template>

<script>
import NProgress from 'nprogress'
import { detail } from '@/api/contract'
import { generateUUID } from '@/utils/util'

export default {
  name: 'loading',
  created() {
    const uuid = this.$route.query.uuid
    const params = this.$store.state.keep.pageParamsMap.get(uuid)
    if (params.handle_param === undefined) {
      this.$router.go(-1)
    }
    const loading = this.$loading({
      lock: true,
      text: '加载中',
      spinner: 'el-icon-loading',
      background: 'rgba(0, 0, 0, 0.6)'
    })
    detail(params.handle_param.id).then(res => {
      let uuid = generateUUID()
      // 如果有父合同则跳转至补充协议界面
      loading.close()
      if (res.data.parent_id) {
        this.$store.commit('keep/PUT_PAGE_PARAMS', {
          uuid: uuid,
          data: {
            handle_param: params.handle_param,
            is_update: true
          }
        })
        this.$store.dispatch('tagsView/closePageTo', {
          closeName: this.$route.name,
          toPath: {
            name: 'personal_handler_contract_apply_update',
            query: {
              uuid
            }
          }
        })
      } else {
        // 没有则跳转至合同详情页
        this.$store.commit('keep/PUT_PAGE_PARAMS', {
          uuid: uuid,
          data: {
            handle_param: params.handle_param
          }
        })
        this.$store.dispatch('tagsView/closePageTo', {
          closeName: this.$route.name,
          toPath: {
            name: 'personal_handler_contract_apply_check',
            query: {
              uuid
            }
          }
        })
      }
    })
  },
  // beforeRouteEnter(to, from, next) {
  //   NProgress.done()
  //   next()
  // }
}
</script>

<style scoped>

</style>
